<template>
  <d2-container>
    <el-form :model="gameDto" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-row>
        <el-col :span="12">
          <el-form-item label="游戏名称" prop="gameName">
            <el-input v-model="gameDto.gameName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="游戏图片" prop="gameName">
            <el-input v-model="gameDto.imgUrl"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="游戏类型" prop="gameName">
            <el-select v-model="gameDto.gameCategoryId" placeholder="请选择游戏类型">
              <el-option label="区域一" value="shanghai"></el-option>
              <el-option label="区域二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="游戏图片" prop="gameName">
            <el-input v-model="gameDto.imgUrl"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="游戏介绍" prop="gameName">
            <el-input type="textarea" v-model="gameDto.gameIntro"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="版本介绍" prop="gameName">
            <el-input type="textarea" v-model="gameDto.versionIntro"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="配置需求" prop="gameName">
            <el-input type="textarea" v-model="gameDto.configRequire"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </d2-container>
</template>

<script>
import { doPost } from '@/api'

export default {
  name: 'game-add',
  data () {
    return {
      gameDto: {
        gameName: null,
        imgUrl: null,
        gameIntro: null,
        versionIntro: null,
        configRequire: null,
        gameCategoryId: null,
        releaseDate: null,
        favorCount: null,
        visitCount: null,
        videoUrl: null,
        newbee: null,
        activeCodeOld: null,
        activeCodeNew: null,
        salesVolume: null,
        downloadVolume: null,
        lastUpdate: null,
        validityDate: null
      },
      rules: {
        gameName: [
          { required: true, message: '请输入游戏名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {

    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          doPost('gameCategory', this.ruleForm).then(res => {
            if (res) {
              this.$message.success('添加成功！')
            } else {
              this.$message.error('添加成功！')
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>

</style>
